package com.xmb.wechat.delegate;

import android.app.Activity;
import android.graphics.Typeface;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.blankj.utilcode.util.SizeUtils;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.xmb.wechat.R;
import com.xmb.wechat.baserecyclerview.BaseRecyclerViewManager;
import com.xmb.wechat.common.Constant;
import com.xmb.wechat.bean.PayProofBean;
import com.xmb.wechat.util.MoneyFormat;
import com.xmb.wechat.util.WechatDateFormat;
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author lijiangop
 * @CreateTime 2020/4/22 11:08
 */
public class PayProofDetailDelegate extends BaseRecyclerViewManager {

    private Typeface mTf;

    public PayProofDetailDelegate(Activity activity) {
        super(activity);
    }

    @Override
    public BaseQuickAdapter initAdapter() {
        return new PayProofDetailAdapter(new ArrayList<>());
    }

    class PayProofDetailAdapter extends BaseMultiItemQuickAdapter<PayProofBean, BaseViewHolder> {
        /**
         * Same as QuickAdapter#QuickAdapter(Context,int) but with
         * some initialization data.
         *
         * @param data A new list is created out of this one to avoid mutable list
         */
        PayProofDetailAdapter(List<PayProofBean> data) {
            super(data);
            addItemType(0, R.layout.item_pay_proof_detail_time);
            addItemType(Constant.PayProofType.TYPE_WITHDRAW_START, R.layout.item_pay_proof_detail_withdraw_start);
            addItemType(Constant.PayProofType.TYPE_WITHDRAW_FINISH, R.layout.item_pay_proof_detail_withdraw_finish);
            addItemType(Constant.PayProofType.TYPE_QRCODE_FINISH_NOTIFICATION, R.layout.item_pay_proof_qr);
            addItemType(Constant.PayProofType.TYPE_PAY_PROOF_GR, R.layout.item_pay_proof_detail_gr);
            addItemType(Constant.PayProofType.TYPE_PAY_PROOF_SH, R.layout.item_pay_proof_detail_sh);
        }

        @Override
        protected void convert(BaseViewHolder helper, PayProofBean item) {
            switch (item.getType()) {
                case 0:
                    helper.setText(R.id.tv_time, WechatDateFormat.formatInsideChat(item.getMsgTime(), context));
                    break;
                case Constant.PayProofType.TYPE_WITHDRAW_START:
                    helper.setText(R.id.tv_time, WechatDateFormat.formatWithOutYear(item.getMsgTime()));
                    helper.setText(R.id.tv_money, MoneyFormat.formatMoney(item.getMoney()));
                    helper.setText(R.id.tv_bank, item.getBankCard());
                    helper.setText(R.id.tv_start_time, item.getStartTime());
                    helper.setText(R.id.tv_finish_time, item.getFinishTime());
                    break;
                case Constant.PayProofType.TYPE_WITHDRAW_FINISH:
                    helper.setText(R.id.tv_time, WechatDateFormat.formatWithOutYear(item.getMsgTime()));
                    helper.setText(R.id.tv_money, MoneyFormat.formatMoney(item.getMoney()));
                    helper.setText(R.id.tv_bank, item.getBankCard());
                    helper.setText(R.id.tv_start_time, item.getStartTime());
                    helper.setText(R.id.tv_finish_time, item.getFinishTime());
                    break;
                case Constant.PayProofType.TYPE_QRCODE_FINISH_NOTIFICATION:
                    if (mTf == null)
                        mTf = Typeface.createFromAsset(context.getAssets(), "fonts/WeChatLqNumber.ttf");
                    TextView tvMoney1 = helper.getView(R.id.tv_money);
                    tvMoney1.setTypeface(mTf);
                    TextView tvMoneyTag1 = helper.getView(R.id.tv_money_tag);
                    tvMoneyTag1.setTypeface(mTf);
                    //内容
                    tvMoney1.setText(MoneyFormat.formatMoney(item.getMoney()));
                    helper.setText(R.id.tv_collect, "今日第" + item.getCountNumber() + "笔收款，共计 ¥ " + item.getCountMoney());
                    break;
                case Constant.PayProofType.TYPE_PAY_PROOF_GR:
                    if (mTf == null)
                        mTf = Typeface.createFromAsset(context.getAssets(), "fonts/WeChatLqNumber.ttf");
                    TextView tvMoney2 = helper.getView(R.id.tv_money);
                    tvMoney2.setTypeface(mTf);
                    TextView tvMoneyTag2 = helper.getView(R.id.tv_money_tag);
                    tvMoneyTag2.setTypeface(mTf);
                    //内容
                    tvMoney2.setText(MoneyFormat.formatMoney(item.getMoney()));
                    helper.setText(R.id.tv_name, item.getReceiveName());
                    helper.setText(R.id.tv_pay_type, item.getPayType());
                    break;
                case Constant.PayProofType.TYPE_PAY_PROOF_SH:
                    if (mTf == null)
                        mTf = Typeface.createFromAsset(context.getAssets(), "fonts/WeChatLqNumber.ttf");
                    TextView tvMoney3 = helper.getView(R.id.tv_money);
                    tvMoney3.setTypeface(mTf);
                    TextView tvMoneyTag3 = helper.getView(R.id.tv_money_tag);
                    tvMoneyTag3.setTypeface(mTf);
                    //内容
                    tvMoney3.setText(MoneyFormat.formatMoney(item.getMoney()));
                    helper.setText(R.id.tv_name, item.getReceiveName());
                    helper.setText(R.id.tv_pay_type, item.getPayType());
                    break;
            }
        }
    }

    @Override
    protected RecyclerView.ItemDecoration getItenDecoration() {
        return new HorizontalDividerItemDecoration.Builder(context).size(SizeUtils.dp2px(8)).color(ContextCompat.getColor(context, R.color.transparent)).build();
    }
}
